function collect(mid) {
    $.post("api/collect", {
            mid: mid
        },
        function (data, status) {
            alert(data)
        });
}

function uncollect(mid) {
    $.post("api/uncollect", {
            mid: mid
        },
        function (data, status) {
            alert(data)
            console.log(mid, "succeed")
            location.reload();
        });
}

function isLogin() {
    $.post("api/islogin", {},
        function (data, status) {
            if (!data) {
                alert("请登录账号后使用。")
            }
        });
}


//记录分数 全局变量
let req = {
    mid:0,
    score:0,
    name:''
}

function rank(mid, name) {
    $.post("api/islogin", {}, function (res) {
        if(res){
            var obj = document.getElementById("popup-box")
            console.log(obj.childNodes[0].childNodes[1].textContent)
            obj.childNodes[0].childNodes[1].textContent = name
            obj.style.zIndex = 10;

            req.mid = mid
            req.name = name
            console.log(mid, name)
        }else{
            alert("请登录账号后使用。")
        }
    })
}

function ranking(score) {
    req.score = score
    for (var i = 1; i <= 5; i++) {
        var obj = document.getElementById('circle' + i)
        if (i <= Number(score)) {
            obj.setAttribute("class", "selected");
        } else {
            obj.setAttribute("class", "");
        }
    }
}

function confirmRank() {
    var obj = document.getElementById("popup-box")
    var name = obj.childNodes[0].childNodes[1].textContent
    $.post("api/ranking", req,
    function (data, status) {
        if(data.errcode <0){
            alert(data.errmsg)
        }
    });
    //评分完成后
    cancelRank();
    if(window.location.pathname='/rank'){
        console.log('reload')
        window.location.reload();
    }
}

function cancelRank() {
    var obj = document.getElementById("popup-box")
    obj.style.zIndex = -2;
    for (var i = 1; i <= 5; i++) {
        var obj = document.getElementById('circle' + i)
        obj.setAttribute("class", "");
    }
}